package it.evento.manager;

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.FacebookClient.AccessToken;

/**
 *
 * @author Ilo
 */
public class FacebookManager {

    public static final String FB_APP_ID = "234575533340005";
    public static final String FB_CLIENT_TOKEN = "eddc4ed9fadfe9b3038389afc2379db4";
    public static final String FB_SECRET = "8d4c1cfefac7526d9e860bf863c11fd9";
    
    private FacebookClient service;
    public AccessToken accessToken;

    public FacebookManager() {
        this.service = null;
    }

    public FacebookManager(FacebookClient client) {
        this.service = client;
    }
    
    public FacebookClient getFacebookClient() {
        return getFacebookClient(true);
    }
    
    public AccessToken getAppAccessToken() {
        this.accessToken = new DefaultFacebookClient().obtainAppAccessToken(FB_APP_ID, FB_SECRET);
        return accessToken;
    }

    public FacebookClient getFacebookClient(boolean securityAccess) {
        if(securityAccess) {
            // Get added security by using your app secret:
            service = new DefaultFacebookClient(FB_CLIENT_TOKEN, FB_SECRET);
        }
        else {
            // DefaultFacebookClient is the FacebookClient implementation
            // that ships with RestFB. You can customize it by passing in
            // custom JsonMapper and WebRequestor implementations, or simply
            // write your own FacebookClient instead for maximum control.
            service = new DefaultFacebookClient(FB_CLIENT_TOKEN);
        }
        
        return service;
    }
    
    public FacebookClient getPublicOnlyFacebookClient() {
        // It's also possible to create a client that can only access
        // publicly-visible data - no access token required. 
        // Note that many of the examples below will not work unless you supply an access token! 
        service = new DefaultFacebookClient();
        
        return service;
    }

}
